﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System;
using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using Gallio.Framework;
using DotNetNuke.Tests.UI.WatiN.Utilities;
using System.Configuration;
using WatiN.Core.DialogHandlers;
using DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects;
using System.IO;
using System.Reflection;




namespace DotNetNuke.Tests.UI.WatiN.AdministratorTests
{
    [TestFixture]

    public class AdminFileManagerTests : ATBase
    {
        public bool LanguagePackInstalled = false;

        #region Test Setup and TearDown

        [SetUp]
        public void SetUp()
        {

            SetUpTest();
        }

        [TearDown]
        public void TearDown()
        {
            //Clean up the folders
            if (Directory.Exists(PhysicalPath + @"\Portals\0\Test Folder"))
            {
                Directory.Delete(PhysicalPath + @"\Portals\0\Test Folder", true);
            }
            if (Directory.Exists(PhysicalPath + @"\Portals\0\Secure FS"))
            {
                Directory.Delete(PhysicalPath + @"\Portals\0\Secure FS", true);
            }
            if (Directory.Exists(PhysicalPath + @"\Portals\0\Secure DB"))
            {
                Directory.Delete(PhysicalPath + @"\Portals\0\Secure DB", true);
            }
            if (Directory.Exists(PhysicalPath + @"\Portals\0\Test Database"))
            {
                Directory.Delete(PhysicalPath + @"\Portals\0\Test Database", true);
            }
            
            TearDownTest();
        }

        #endregion

        #region Tests

        [Test]
        [DependsOn("Access_File_Manager")]
        public void Adding_Folders_Standard_File_System()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
            FileManagerPage fileManager = new FileManagerPage(homePage);
            fileManager.FolderExpandImage.Click();
            fileManager.FolderTypeSelectList.Select("Standard");
            fileManager.FolderNameTextField.Value = "Test Folder";
            fileManager.AddFolderButton.Click();
            Span newFolderSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));
            System.Threading.Thread.Sleep(1500);

            //Assert
            Assert.IsTrue(newFolderSpan.Exists);
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains(@"Portal Root\Test Folder"));
            fileManager.FolderTypeSelectList.Select("Standard");
            fileManager.FolderNameTextField.Value = "Child Folder";
            fileManager.AddFolderButton.Click();
            Span childFolderSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Child Folder"));
            Assert.IsTrue(childFolderSpan.Exists);
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains(@"Portal Root\Test Folder\Child Folder"));
            Directory.Delete(PhysicalPath + @"\Portals\0\Test Folder", true);
        }

        [Test]
        [DependsOn("Access_File_Manager")]
        public void Adding_Folders_Secure_File_System()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
            FileManagerPage fileManager = new FileManagerPage(homePage);
            fileManager.FolderExpandImage.Click();
            fileManager.FolderTypeSelectList.Select("Secure");
            fileManager.FolderNameTextField.Value = "Secure Test Folder";
            fileManager.AddFolderButton.Click();
            Span newFolderSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure Test Folder"));
            //Assert
            Assert.IsTrue(newFolderSpan.Exists);
            Assert.IsTrue(fileManager.SecureFolderIcons.Count == 1);
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains(@"Portal Root\Secure Test Folder"));
            fileManager.FolderTypeSelectList.Select("Secure");
            fileManager.FolderNameTextField.Value = "Secure Child Folder";
            fileManager.AddFolderButton.Click();
            Span childFolderSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure Child Folder"));
            Assert.IsTrue(childFolderSpan.Exists);
            Assert.IsTrue(fileManager.SecureFolderIcons.Count == 2);
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains(@"Portal Root\Secure Test Folder\Secure Child Folder"));
            Directory.Delete(PhysicalPath + @"\Portals\0\Secure Test Folder", true);
        }

        [Test]
        [DependsOn("Access_File_Manager")]
        public void Adding_Secure_Database()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
            FileManagerPage fileManager = new FileManagerPage(homePage);
            fileManager.FolderExpandImage.Click();
            fileManager.FolderTypeSelectList.Select("Database");
            fileManager.FolderNameTextField.Value = "Secure Database";
            fileManager.AddFolderButton.Click();
            Span newFolderSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure Database"));
            //Assert
            Assert.IsTrue(newFolderSpan.Exists);
            Assert.IsTrue(fileManager.SecureDatabaseIcons.Count == 1);
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains(@"Portal Root\Secure Database"));
            fileManager.FolderTypeSelectList.Select("Database");
            fileManager.FolderNameTextField.Value = "Secure Child Database";
            fileManager.AddFolderButton.Click();
            Span childFolderSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure Child Database"));
            Assert.IsTrue(childFolderSpan.Exists);
            Assert.IsTrue(fileManager.SecureDatabaseIcons.Count == 2);
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains(@"Portal Root\Secure Database\Secure Child Database"));
            Directory.Delete(PhysicalPath + @"\Portals\0\Secure Database", true);
        }

        [Test]
        [DependsOn("Access_File_Manager")]
        public void Upload_Files()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
            FileManagerPage fileManager = new FileManagerPage(homePage);
            fileManager.FolderExpandImage.Click();
            fileManager.FolderTypeSelectList.Select("Standard");
            fileManager.FolderNameTextField.Value = "Test Folder";
            fileManager.AddFolderButton.Click();
            fileManager.PortalRootSpan.Click();
            fileManager.FolderTypeSelectList.Select("Secure");
            fileManager.FolderNameTextField.Value = "Secure Folder";
            fileManager.AddFolderButton.Click();
            fileManager.PortalRootSpan.Click();
            fileManager.FolderTypeSelectList.Select("Database");
            fileManager.FolderNameTextField.Value = "Secure Database";
            fileManager.AddFolderButton.Click();

            //Act & Assert
            Span currentFolderSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));
            //currentFolderSpan.Click();
            System.Threading.Thread.Sleep(1500);
            fileManager.UploadImage.ClickNoWait();
            System.Threading.Thread.Sleep(1500);
            fileManager.UploadDestinationSelectList.Select("Test Folder");
            System.Threading.Thread.Sleep(500);
            fileManager.SelectFileDialog.Set(TestEnvironment.FilePath);
            fileManager.UploadSelectedFileLink.ClickNoWait();
            System.Threading.Thread.Sleep(1000);
            fileManager.ReturnLink.Click();
            fileManager.FolderExpandImage.ClickNoWait();
            currentFolderSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));
            System.Threading.Thread.Sleep(2500);
            currentFolderSpan.Click();
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));

            fileManager.UploadImage.Click();
            fileManager.UploadDestinationSelectList.Select("Secure Folder");
            System.Threading.Thread.Sleep(500);
            fileManager.SelectFileDialog.Set(TestEnvironment.FilePath);
            fileManager.UploadSelectedFileLink.Click();
            System.Threading.Thread.Sleep(1000);
            fileManager.ReturnLink.Click();
            fileManager.FolderExpandImage.Click();
            currentFolderSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure Folder"));
            currentFolderSpan.Click();
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));

            fileManager.UploadImage.Click();
            fileManager.UploadDestinationSelectList.Select("Secure Database");
            System.Threading.Thread.Sleep(500);
            fileManager.SelectFileDialog.Set(TestEnvironment.FilePath);
            fileManager.UploadSelectedFileLink.Click();
            System.Threading.Thread.Sleep(1000);
            fileManager.ReturnLink.Click();
            fileManager.FolderExpandImage.Click();
            currentFolderSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure Database"));
            currentFolderSpan.Click();
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));

            //Clean up the folders
            Directory.Delete(PhysicalPath + @"\Portals\0\Test Folder", true);
            Directory.Delete(PhysicalPath + @"\Portals\0\Secure Folder", true);
            Directory.Delete(PhysicalPath + @"\Portals\0\Secure Database", true);
        }

        [Test]
        public void Access_File_Manager()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Act
            ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
            FileManagerPage fileManager = new FileManagerPage(homePage);
            System.Threading.Thread.Sleep(1500);

            //Assert 
            Assert.IsTrue(homePage.ModuleTitleSpans.Count == 1);
            Assert.IsTrue(fileManager.ModuleTitleSpan.InnerHtml.Contains("File Manager"));
            Assert.IsTrue(fileManager.FileManagerTable.Exists);
        }

        [Test]
        public void Access_Admin_File_Manager_Secure_Database()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Act
            ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
            FileManagerPage fileManager = new FileManagerPage(homePage);
            fileManager.FolderTypeSelectList.Select("Database");
            fileManager.RefreshImage.Click();

            //Assert 
            Assert.IsTrue(fileManager.FolderTypeSelectList.SelectedItem.Equals("Database"));
        }

        [Test]
        public void Access_Admin_File_Manager_Secure_File_System()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Act
            ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
            FileManagerPage fileManager = new FileManagerPage(homePage);
            fileManager.FolderTypeSelectList.Select("Secure");
            fileManager.RefreshImage.Click();

            //Assert 
            Assert.IsTrue(fileManager.FolderTypeSelectList.SelectedItem.Equals("Secure"));
        }

        [Test]
        public void Access_Admin_File_Manager_Standard_File_System()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Act
            ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
            FileManagerPage fileManager = new FileManagerPage(homePage);
            fileManager.FolderTypeSelectList.Select("Standard");
            fileManager.RefreshImage.Click();

            //Assert 
            Assert.IsTrue(fileManager.FolderTypeSelectList.SelectedItem.Equals("Standard"));
        }

        [Test]
        [DependsOn("Upload_Files")]
        [DependsOn("Adding_Folders_Standard_File_System")]
        public void Move_File_Standard_FS_To_Standard_FS()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
            FileManagerPage fileManager = new FileManagerPage(homePage);

            //Create two Standard file systems
            fileManager.FolderExpandImage.Click();
            fileManager.FolderTypeSelectList.Select("Standard");
            fileManager.FolderNameTextField.Value = "File System";
            fileManager.AddFolderButton.Click();
            fileManager.PortalRootSpan.Click();
            fileManager.FolderTypeSelectList.Select("Standard");
            fileManager.FolderNameTextField.Value = "Test Folder";
            fileManager.AddFolderButton.Click();

            //Add a file to one of the folders 
            fileManager.UploadImage.Click();
            fileManager.UploadDestinationSelectList.Select("File System");
            System.Threading.Thread.Sleep(500);
            fileManager.SelectFileDialog.Set(TestEnvironment.FilePath);
            fileManager.UploadSelectedFileLink.Click();
            System.Threading.Thread.Sleep(500);
            fileManager.ReturnLink.Click();
            fileManager.FolderExpandImage.Click();
            Span fileSystemSpan = fileManager.FoldersSpan.Span(Find.ByTitle("File System"));

            //Act 
            //Move the file
            fileSystemSpan.Click();
            Span testFolderSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));
            fileManager.SelectFileCheckbox.Checked = true;
            ConfirmDialogHandler dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                fileManager.MoveFileImage.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            testFolderSpan.Click();
            fileManager.MoveFileOKButton.Click();

            //Assert
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains("Test Folder"));
            Assert.IsTrue(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));
            fileSystemSpan = fileManager.FoldersSpan.Span(Find.ByTitle("File System"));
            fileSystemSpan.Click();
            Assert.IsFalse(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));

            //Move the File back 
            testFolderSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));
            testFolderSpan.Click();
            fileSystemSpan = fileManager.FoldersSpan.Span(Find.ByTitle("File System"));
            fileManager.SelectFileCheckbox.Checked = true;
            dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                fileManager.MoveFileImage.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            fileSystemSpan.Click();
            fileManager.MoveFileOKButton.Click();

            //Assert
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains("File System"));
            Assert.IsTrue(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));
            testFolderSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));
            testFolderSpan.Click();
            Assert.IsFalse(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));

            //Clean up the folders
            Directory.Delete(PhysicalPath + @"\Portals\0\Test Folder", true);
            Directory.Delete(PhysicalPath + @"\Portals\0\File System", true);
        }

        [Test]
        [DependsOn("Upload_Files")]
        [DependsOn("Adding_Folders_Standard_File_System")]
        [DependsOn("Adding_Secure_Database")]
        public void Move_File_Standard_FS_To_Secure_DB()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
            FileManagerPage fileManager = new FileManagerPage(homePage);

            //Create two Standard file systems
            fileManager.FolderExpandImage.Click();
            fileManager.FolderTypeSelectList.Select("Standard");
            fileManager.FolderNameTextField.Value = "Test Folder";
            fileManager.AddFolderButton.Click();
            fileManager.PortalRootSpan.Click();
            fileManager.FolderTypeSelectList.Select("Database");
            fileManager.FolderNameTextField.Value = "Secure DB";
            fileManager.AddFolderButton.Click();

            //Add a file to one of the folders 
            fileManager.UploadImage.Click();
            fileManager.UploadDestinationSelectList.Select("Test Folder");
            System.Threading.Thread.Sleep(500);
            fileManager.SelectFileDialog.Set(TestEnvironment.FilePath);
            fileManager.UploadSelectedFileLink.Click();
            System.Threading.Thread.Sleep(500);
            fileManager.ReturnLink.Click();
            fileManager.FolderExpandImage.Click();
            Span fileSystemSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));

            //Act 
            //Move the file
            fileSystemSpan.Click();
            Span databaseSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure DB"));
            fileManager.SelectFileCheckbox.Checked = true;
            ConfirmDialogHandler dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                fileManager.MoveFileImage.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            databaseSpan.Click();
            fileManager.MoveFileOKButton.Click();

            //Assert
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains("Secure DB"));
            Assert.IsTrue(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));
            fileSystemSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));
            fileSystemSpan.Click();
            Assert.IsFalse(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));

            //Move the file back 
            databaseSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure DB"));
            databaseSpan.Click();
            fileSystemSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));
            fileManager.SelectFileCheckbox.Checked = true;
            dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                fileManager.MoveFileImage.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            fileSystemSpan.Click();
            fileManager.MoveFileOKButton.Click();

            //Assert
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains("Test Folder"));
            Assert.IsTrue(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));
            databaseSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure DB"));
            databaseSpan.Click();
            Assert.IsFalse(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));

            //Clean up the folders
            Directory.Delete(PhysicalPath + @"\Portals\0\Test Folder", true);
            Directory.Delete(PhysicalPath + @"\Portals\0\Secure DB", true);
        }

        [Test]
        [DependsOn("Upload_Files")]
        [DependsOn("Adding_Folders_Standard_File_System")]
        [DependsOn("Adding_Folders_Secure_File_System")]
        public void Move_File_Standard_FS_To_Secure_FS()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
            FileManagerPage fileManager = new FileManagerPage(homePage);

            //Create two Standard file systems
            fileManager.FolderExpandImage.Click();
            fileManager.FolderTypeSelectList.Select("Standard");
            fileManager.FolderNameTextField.Value = "Test Folder";
            fileManager.AddFolderButton.Click();
            fileManager.PortalRootSpan.Click();
            fileManager.FolderTypeSelectList.Select("Secure");
            fileManager.FolderNameTextField.Value = "Secure FS";
            fileManager.AddFolderButton.Click();

            //Add a file to one of the folders 
            fileManager.UploadImage.Click();
            fileManager.UploadDestinationSelectList.Select("Test Folder");
            System.Threading.Thread.Sleep(500);
            fileManager.SelectFileDialog.Set(TestEnvironment.FilePath);
            fileManager.UploadSelectedFileLink.Click();
            System.Threading.Thread.Sleep(500);
            fileManager.ReturnLink.Click();
            fileManager.FolderExpandImage.Click();
            Span fileSystemSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));

            //Act 
            //Move the file
            fileSystemSpan.Click();
            Span secureSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure FS"));
            fileManager.SelectFileCheckbox.Checked = true;
            ConfirmDialogHandler dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                fileManager.MoveFileImage.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            secureSpan.Click();
            fileManager.MoveFileOKButton.Click();

            //Assert
            System.Threading.Thread.Sleep(5000);
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains("Secure FS"));
            Assert.IsTrue(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));
            fileSystemSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));
            fileSystemSpan.Click();
            Assert.IsFalse(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));

            //Move the file back
            secureSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure FS"));
            secureSpan.Click();
            fileSystemSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));
            fileManager.SelectFileCheckbox.Checked = true;
            dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                fileManager.MoveFileImage.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            fileSystemSpan.Click();
            fileManager.MoveFileOKButton.Click();

            //Assert
            System.Threading.Thread.Sleep(5000);
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains("Test Folder"));
            Assert.IsTrue(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));
            secureSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure FS"));
            secureSpan.Click();
            Assert.IsFalse(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));            
        }

        [Test]
        [DependsOn("Upload_Files")]
        [DependsOn("Adding_Folders_Secure_File_System")]
        public void Move_File_Secure_FS_To_Secure_FS()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
            FileManagerPage fileManager = new FileManagerPage(homePage);

            //Create two Standard file systems
            fileManager.FolderExpandImage.Click();
            fileManager.FolderTypeSelectList.Select("Secure");
            fileManager.FolderNameTextField.Value = "Test Folder";
            fileManager.AddFolderButton.Click();
            fileManager.PortalRootSpan.Click();
            fileManager.FolderTypeSelectList.Select("Secure");
            fileManager.FolderNameTextField.Value = "Secure FS";
            fileManager.AddFolderButton.Click();

            //Add a file to one of the folders 
            fileManager.UploadImage.Click();
            fileManager.UploadDestinationSelectList.Select("Test Folder");
            System.Threading.Thread.Sleep(500);
            fileManager.SelectFileDialog.Set(TestEnvironment.FilePath);
            fileManager.UploadSelectedFileLink.Click();
            System.Threading.Thread.Sleep(500);
            fileManager.ReturnLink.Click();
            fileManager.FolderExpandImage.Click();
            Span fileSystemSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));

            //Act 
            //Move the file
            fileSystemSpan.Click();
            Span secureSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure FS"));
            fileManager.SelectFileCheckbox.Checked = true;
            ConfirmDialogHandler dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                fileManager.MoveFileImage.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            secureSpan.Click();
            fileManager.MoveFileOKButton.Click();

            //Assert
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains("Secure FS"));
            Assert.IsTrue(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));
            fileSystemSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));
            fileSystemSpan.Click();
            Assert.IsFalse(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));

            //Move the file back
            secureSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure FS"));
            secureSpan.Click();
            fileSystemSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));
            fileManager.SelectFileCheckbox.Checked = true;
            dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                fileManager.MoveFileImage.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            fileSystemSpan.Click();
            fileManager.MoveFileOKButton.Click();

            //Assert
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains("Test Folder"));
            Assert.IsTrue(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));
            secureSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure FS"));
            secureSpan.Click();
            Assert.IsFalse(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));

        }

        [Test]
        [DependsOn("Upload_Files")]
        [DependsOn("Adding_Folders_Secure_File_System")]
        [DependsOn("Adding_Secure_Database")]
        public void Move_File_Secure_FS_To_Secure_DB()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
            FileManagerPage fileManager = new FileManagerPage(homePage);

            //Create two Standard file systems
            fileManager.FolderExpandImage.Click();
            fileManager.FolderTypeSelectList.Select("Secure");
            fileManager.FolderNameTextField.Value = "Test Folder";
            fileManager.AddFolderButton.Click();
            fileManager.PortalRootSpan.Click();
            fileManager.FolderTypeSelectList.Select("Database");
            fileManager.FolderNameTextField.Value = "Secure DB";
            fileManager.AddFolderButton.Click();

            //Add a file to one of the folders 
            fileManager.UploadImage.Click();
            fileManager.UploadDestinationSelectList.Select("Test Folder");
            System.Threading.Thread.Sleep(500);
            fileManager.SelectFileDialog.Set(TestEnvironment.FilePath);
            fileManager.UploadSelectedFileLink.Click();
            System.Threading.Thread.Sleep(500);
            fileManager.ReturnLink.Click();
            fileManager.FolderExpandImage.Click();
            Span fileSystemSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));

            //Act 
            //move the file
            fileSystemSpan.Click();
            Span databaseSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure DB"));
            fileManager.SelectFileCheckbox.Checked = true;
            ConfirmDialogHandler dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                fileManager.MoveFileImage.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            databaseSpan.Click();
            fileManager.MoveFileOKButton.Click();

            //Assert
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains("Secure DB"));
            Assert.IsTrue(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));
            fileSystemSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));
            fileSystemSpan.Click();
            Assert.IsFalse(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));

            //Move the file back 
            databaseSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure DB"));
            databaseSpan.Click();
            fileSystemSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Folder"));
            fileManager.SelectFileCheckbox.Checked = true;
            dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                fileManager.MoveFileImage.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            fileSystemSpan.Click();
            fileManager.MoveFileOKButton.Click();

            //Assert
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains("Test Folder"));
            Assert.IsTrue(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));
            databaseSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure DB"));
            databaseSpan.Click();
            Assert.IsFalse(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));


        }

        [Test]
        [DependsOn("Upload_Files")]
        [DependsOn("Adding_Secure_Database")]
        public void Move_File_Secure_DB_To_Secure_DB()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
            FileManagerPage fileManager = new FileManagerPage(homePage);

            //Create two Standard file systems
            fileManager.FolderExpandImage.Click();
            fileManager.FolderTypeSelectList.Select("Database");
            fileManager.FolderNameTextField.Value = "Test Database";
            fileManager.AddFolderButton.Click();
            System.Threading.Thread.Sleep(1500);
            fileManager.PortalRootSpan.Click();
            System.Threading.Thread.Sleep(1500);
            fileManager.FolderTypeSelectList.Select("Database");
            fileManager.FolderNameTextField.Value = "Secure DB";
            fileManager.AddFolderButton.Click();

            //Add a file to one of the folders 
            fileManager.UploadImage.Click();
            fileManager.UploadDestinationSelectList.Select("Test Database");
            System.Threading.Thread.Sleep(500);
            fileManager.SelectFileDialog.Set(TestEnvironment.FilePath);
            fileManager.UploadSelectedFileLink.Click();
            System.Threading.Thread.Sleep(500);
            fileManager.ReturnLink.Click();
            fileManager.FolderExpandImage.Click();
            Span testDBSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Database"));

            //Act
            //Move the file
            testDBSpan.ClickNoWait();
            System.Threading.Thread.Sleep(1000);
            Span databaseSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure DB"));
            fileManager.SelectFileCheckbox.Checked = true;
            ConfirmDialogHandler dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                fileManager.MoveFileImage.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            databaseSpan.Click();
            fileManager.MoveFileOKButton.Click();

            //Assert
            System.Threading.Thread.Sleep(1500);
            fileManager.FolderExpandImage.Click();
            System.Threading.Thread.Sleep(5000);
            databaseSpan.Refresh();
            databaseSpan.Click();
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains("Secure DB"));
            Assert.IsTrue(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));
            testDBSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Database"));
            testDBSpan.Click();
            System.Threading.Thread.Sleep(1500);
            Assert.IsFalse(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));

            //Move the file back 
            databaseSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure DB"));
            databaseSpan.Click();
            testDBSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Test Database"));
            fileManager.SelectFileCheckbox.Checked = true;
            dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                fileManager.MoveFileImage.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            testDBSpan.Click();
            fileManager.MoveFileOKButton.Click();
            System.Threading.Thread.Sleep(1500);

            //Assert
            Assert.IsTrue(fileManager.CurrentFolderSpan.InnerHtml.Contains("Test Database"));
            Assert.IsTrue(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));
            databaseSpan = fileManager.FoldersSpan.Span(Find.ByTitle("Secure DB"));
            databaseSpan.Click();
            Assert.IsFalse(fileManager.FolderContentsTable.InnerHtml.Contains(TestEnvironment.TestFileName));



            //Clean up the folders
            Directory.Delete(PhysicalPath + @"\Portals\0\Test Database", true);
            Directory.Delete(PhysicalPath + @"\Portals\0\Secure DB", true);
        }

        #endregion
    }
}